package com.byq.mm.abstractx.engine;


import com.byq.mm.abstractx.cluster.client.ClusterClient;
import com.byq.mm.abstractx.cluster.client.DeviceClient;
import com.byq.mm.abstractx.identifier.IdentifierCreator;
import com.byq.mm.abstractx.protocol.Interaction;

public class InteractionProcessor {
	CoreEnvironment env;
	public InteractionProcessor(CoreEnvironment env) {
		super();
		this.env = env;
	}
	public void process(Interaction i, String from){
		if(i.isCommand()){
			env.getServerDeviceManager().getServerAccessController().onCommand(i, from);
			
			
		}
		if(i.isReport()){
			String cid = IdentifierCreator.createIdentifier(from.split("/")[0], i.from);
			DeviceClient client = env.getClientDeviceManager().getDeviceClient(cid);
			if(client == null)
				return;
			ClusterClient cs = client.getClusterClient(i.cluster);
			if(cs == null)
				return;
			cs.onReport(i);
		}
	}
}
